<?php

namespace App\Http\Controllers\Wap;

use App\Models\Car;
use App\Models\Order;
use Illuminate\Http\Request;

class CarController extends WapController
{
    // 查看鉴定报告
    public function seeAppraisalReport(Request $request, Car $model){
        $uid = $request->get('user')->id;
        $request_data = $request->all();
        $car_id = $request_data['car_id'];
        // 先确认是否已生成了鉴定报告
        $res = $model::where('id', $car_id)->where('appraisal_report', '<>','')->first();
        if(empty($res)){
            return $this->failed('未生成鉴定报告')->setStatusCode(400);
        }
        $res->makeVisible('appraisal_report');
        // 确认是否已付费过鉴定报告

        $is_appraisal = Order::where('type',2)->where('car_id', $car_id)->where('user_id', $uid)->whereNotNull('paid_at')->first();
        if($is_appraisal){
            return $this->success(['url'=> $res->appraisal_report]);
        }
        return $this->message('您还未购买此鉴定服务');
    }


}
